{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId = \"lijiahao08\" #学生填写\n",
    "create_facelists_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/{}\" #学生填写\n",
    "subscription_key = \"85019b1c0337446294c317daeb3f435d\" #学生填写\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "  \"name\": \"sample_list07\",\n",
    "  \"userData\": \"xiangce\",\n",
    "  \"recognitionModel\": \"recognition_03\"# 学生填写\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) #学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [409]>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_facelist_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [],\n",
       " 'faceListId': 'lijiahao08',\n",
       " 'name': 'sample_list07',\n",
       " 'userData': 'xiangce'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、Add face\n",
    "add_face_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"http://huangjieqi.gitee.io/picture_storage/EdisonQXF.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"userData\":\"丘某峰\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': 'baeda9f7-fe2e-460b-9f7f-3b1415d7621b',\n",
       "   'userData': '丘某峰'}],\n",
       " 'faceListId': 'lijiahao08',\n",
       " 'name': 'sample_list07',\n",
       " 'userData': 'xiangce'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_facelist_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/lijiahao08\"\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片/函数——可以重复使用相同的功能\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":\"userData\"\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'subscription_key' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-fb90007440fc>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"丘天惠\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"林嘉茵\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"汤玲萍\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"曾雯燕\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"谢依希\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m<ipython-input-1-b3c73ee9d9c1>\u001b[0m in \u001b[0;36mAddFace\u001b[1;34m(img_url, userData)\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mAddFace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0muserData\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0madd_face_url\u001b[0m \u001b[1;33m=\u001b[0m\u001b[1;34m\"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m     \u001b[1;32massert\u001b[0m \u001b[0msubscription_key\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m     headers = {\n\u001b[0;32m      6\u001b[0m         \u001b[1;31m# Request headers\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'subscription_key' is not defined"
     ]
    }
   ],
   "source": [
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/ltco.jpg\",\"李婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg\",\"黄智毅\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg\",\"黄慧文\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg\",\"张铭睿\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/yichenting.jpg\",\"陈婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/coco022.jpg\",\"洪可凡\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lujizhi.png\",\"卢继志\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg\",\"张梓乐\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': 'baeda9f7-fe2e-460b-9f7f-3b1415d7621b',\n",
       "   'userData': '丘某峰'},\n",
       "  {'persistedFaceId': 'f2226c34-8d38-4592-bf43-c26dbe520df6',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '0c9db1fc-402b-44b7-b9f4-dbf30136451c',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': 'e1812223-91f1-4051-babb-127cbf66313a',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '47169bfe-e7a8-4201-a086-448094806553',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '2c4a2338-fd05-47f4-9379-a344c8bf58d1',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '2de67cc6-f2bf-4f55-bb8b-99c9a2441fbf',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': 'fd241e59-37e8-4b2e-9159-8cd0f2db0daf',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '5bf652c3-20bf-49f5-b435-2a6ff56a09e6',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': 'aad9040d-e1a8-4945-9a55-dd01156ea5fe',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'acb7147b-533e-4699-ba5b-82db2494f4f6',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'bd4ff60f-c33a-4e19-810c-d15059be5f5b',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '31e5ec17-b883-4b51-89a9-2db94a5d019b',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'd7b8de6a-0960-424d-b455-06b5dab89ac8',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': 'fdcb99fd-00fe-4094-bc4f-fafee5324491',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': 'fc0e5a29-da02-4a38-babc-03175a3682a8',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'e2c290d5-0e7b-4062-8604-c51a7e99443a',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '2adb504e-2565-4e4d-b336-be3ff77cfebb',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': '23d81189-bac5-470e-8347-e9865d91303e',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': '9b4b0ca3-bcff-4958-a20a-5ae93574dcea',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '48b98458-7be4-400d-ae28-99221d5c78e7',\n",
       "   'userData': '张梓乐'}],\n",
       " 'faceListId': 'lijiahao08',\n",
       " 'name': 'sample_list07',\n",
       " 'userData': 'xiangce'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/facelists/lijiahao08\"\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '2fcb0f2d-8886-4f49-8dc0-d942b66f03fa',\n",
       "  'faceRectangle': {'top': 264, 'left': 207, 'width': 277, 'height': 277}}]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Detect 检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-xls.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'http://huangjieqi.gitee.io/picture_storage/hjq.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': '',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://api-xls.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"2fcb0f2d-8886-4f49-8dc0-d942b66f03fa\",#取上方的faceID\n",
    "    \"faceListId\": \"lijiahao08\",\n",
    "#     \"faceIds\":faceId_02,\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': 'acb7147b-533e-4699-ba5b-82db2494f4f6',\n",
       "  'confidence': 0.29269},\n",
       " {'persistedFaceId': 'd7b8de6a-0960-424d-b455-06b5dab89ac8',\n",
       "  'confidence': 0.20908},\n",
       " {'persistedFaceId': 'e2c290d5-0e7b-4062-8604-c51a7e99443a',\n",
       "  'confidence': 0.17849},\n",
       " {'persistedFaceId': 'aad9040d-e1a8-4945-9a55-dd01156ea5fe',\n",
       "  'confidence': 0.16209},\n",
       " {'persistedFaceId': 'bd4ff60f-c33a-4e19-810c-d15059be5f5b',\n",
       "  'confidence': 0.15023},\n",
       " {'persistedFaceId': '23d81189-bac5-470e-8347-e9865d91303e',\n",
       "  'confidence': 0.101},\n",
       " {'persistedFaceId': '0c9db1fc-402b-44b7-b9f4-dbf30136451c',\n",
       "  'confidence': 0.10034},\n",
       " {'persistedFaceId': '48b98458-7be4-400d-ae28-99221d5c78e7',\n",
       "  'confidence': 0.0999},\n",
       " {'persistedFaceId': 'baeda9f7-fe2e-460b-9f7f-3b1415d7621b',\n",
       "  'confidence': 0.09955},\n",
       " {'persistedFaceId': 'fdcb99fd-00fe-4094-bc4f-fafee5324491',\n",
       "  'confidence': 0.09503}]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>baeda9f7-fe2e-460b-9f7f-3b1415d7621b</td>\n",
       "      <td>丘某峰</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f2226c34-8d38-4592-bf43-c26dbe520df6</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0c9db1fc-402b-44b7-b9f4-dbf30136451c</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>e1812223-91f1-4051-babb-127cbf66313a</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>47169bfe-e7a8-4201-a086-448094806553</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2c4a2338-fd05-47f4-9379-a344c8bf58d1</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2de67cc6-f2bf-4f55-bb8b-99c9a2441fbf</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>fd241e59-37e8-4b2e-9159-8cd0f2db0daf</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5bf652c3-20bf-49f5-b435-2a6ff56a09e6</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>aad9040d-e1a8-4945-9a55-dd01156ea5fe</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>acb7147b-533e-4699-ba5b-82db2494f4f6</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>bd4ff60f-c33a-4e19-810c-d15059be5f5b</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>31e5ec17-b883-4b51-89a9-2db94a5d019b</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>d7b8de6a-0960-424d-b455-06b5dab89ac8</td>\n",
       "      <td>李婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>fdcb99fd-00fe-4094-bc4f-fafee5324491</td>\n",
       "      <td>黄智毅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>fc0e5a29-da02-4a38-babc-03175a3682a8</td>\n",
       "      <td>黄慧文</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>e2c290d5-0e7b-4062-8604-c51a7e99443a</td>\n",
       "      <td>张铭睿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2adb504e-2565-4e4d-b336-be3ff77cfebb</td>\n",
       "      <td>陈婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>23d81189-bac5-470e-8347-e9865d91303e</td>\n",
       "      <td>洪可凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>9b4b0ca3-bcff-4958-a20a-5ae93574dcea</td>\n",
       "      <td>卢继志</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>48b98458-7be4-400d-ae28-99221d5c78e7</td>\n",
       "      <td>张梓乐</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   baeda9f7-fe2e-460b-9f7f-3b1415d7621b      丘某峰\n",
       "1   f2226c34-8d38-4592-bf43-c26dbe520df6      丘天惠\n",
       "2   0c9db1fc-402b-44b7-b9f4-dbf30136451c      林嘉茵\n",
       "3   e1812223-91f1-4051-babb-127cbf66313a      汤玲萍\n",
       "4   47169bfe-e7a8-4201-a086-448094806553      曾雯燕\n",
       "5   2c4a2338-fd05-47f4-9379-a344c8bf58d1      谢依希\n",
       "6   2de67cc6-f2bf-4f55-bb8b-99c9a2441fbf      杨悦聪\n",
       "7   fd241e59-37e8-4b2e-9159-8cd0f2db0daf       周雨\n",
       "8   5bf652c3-20bf-49f5-b435-2a6ff56a09e6      刘瑜鹏\n",
       "9   aad9040d-e1a8-4945-9a55-dd01156ea5fe      陈嘉仪\n",
       "10  acb7147b-533e-4699-ba5b-82db2494f4f6      徐旖芊\n",
       "11  bd4ff60f-c33a-4e19-810c-d15059be5f5b      刘心如\n",
       "12  31e5ec17-b883-4b51-89a9-2db94a5d019b       刘宇\n",
       "13  d7b8de6a-0960-424d-b455-06b5dab89ac8       李婷\n",
       "14  fdcb99fd-00fe-4094-bc4f-fafee5324491      黄智毅\n",
       "15  fc0e5a29-da02-4a38-babc-03175a3682a8      黄慧文\n",
       "16  e2c290d5-0e7b-4062-8604-c51a7e99443a      张铭睿\n",
       "17  2adb504e-2565-4e4d-b336-be3ff77cfebb       陈婷\n",
       "18  23d81189-bac5-470e-8347-e9865d91303e      洪可凡\n",
       "19  9b4b0ca3-bcff-4958-a20a-5ae93574dcea      卢继志\n",
       "20  48b98458-7be4-400d-ae28-99221d5c78e7      张梓乐"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "#facelist里面的数据\n",
    "faceListId_df = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "faceListId_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>acb7147b-533e-4699-ba5b-82db2494f4f6</td>\n",
       "      <td>0.29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>d7b8de6a-0960-424d-b455-06b5dab89ac8</td>\n",
       "      <td>0.20908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>e2c290d5-0e7b-4062-8604-c51a7e99443a</td>\n",
       "      <td>0.17849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>aad9040d-e1a8-4945-9a55-dd01156ea5fe</td>\n",
       "      <td>0.16209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>bd4ff60f-c33a-4e19-810c-d15059be5f5b</td>\n",
       "      <td>0.15023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23d81189-bac5-470e-8347-e9865d91303e</td>\n",
       "      <td>0.10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0c9db1fc-402b-44b7-b9f4-dbf30136451c</td>\n",
       "      <td>0.10034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>48b98458-7be4-400d-ae28-99221d5c78e7</td>\n",
       "      <td>0.09990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>baeda9f7-fe2e-460b-9f7f-3b1415d7621b</td>\n",
       "      <td>0.09955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>fdcb99fd-00fe-4094-bc4f-fafee5324491</td>\n",
       "      <td>0.09503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  acb7147b-533e-4699-ba5b-82db2494f4f6     0.29269\n",
       "1  d7b8de6a-0960-424d-b455-06b5dab89ac8     0.20908\n",
       "2  e2c290d5-0e7b-4062-8604-c51a7e99443a     0.17849\n",
       "3  aad9040d-e1a8-4945-9a55-dd01156ea5fe     0.16209\n",
       "4  bd4ff60f-c33a-4e19-810c-d15059be5f5b     0.15023\n",
       "5  23d81189-bac5-470e-8347-e9865d91303e     0.10100\n",
       "6  0c9db1fc-402b-44b7-b9f4-dbf30136451c     0.10034\n",
       "7  48b98458-7be4-400d-ae28-99221d5c78e7     0.09990\n",
       "8  baeda9f7-fe2e-460b-9f7f-3b1415d7621b     0.09955\n",
       "9  fdcb99fd-00fe-4094-bc4f-fafee5324491     0.09503"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "find_df = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "find_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>acb7147b-533e-4699-ba5b-82db2494f4f6</td>\n",
       "      <td>徐旖芊</td>\n",
       "      <td>0.29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>d7b8de6a-0960-424d-b455-06b5dab89ac8</td>\n",
       "      <td>李婷</td>\n",
       "      <td>0.20908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>e2c290d5-0e7b-4062-8604-c51a7e99443a</td>\n",
       "      <td>张铭睿</td>\n",
       "      <td>0.17849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>aad9040d-e1a8-4945-9a55-dd01156ea5fe</td>\n",
       "      <td>陈嘉仪</td>\n",
       "      <td>0.16209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>bd4ff60f-c33a-4e19-810c-d15059be5f5b</td>\n",
       "      <td>刘心如</td>\n",
       "      <td>0.15023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23d81189-bac5-470e-8347-e9865d91303e</td>\n",
       "      <td>洪可凡</td>\n",
       "      <td>0.10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0c9db1fc-402b-44b7-b9f4-dbf30136451c</td>\n",
       "      <td>林嘉茵</td>\n",
       "      <td>0.10034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>48b98458-7be4-400d-ae28-99221d5c78e7</td>\n",
       "      <td>张梓乐</td>\n",
       "      <td>0.09990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>baeda9f7-fe2e-460b-9f7f-3b1415d7621b</td>\n",
       "      <td>丘某峰</td>\n",
       "      <td>0.09955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>fdcb99fd-00fe-4094-bc4f-fafee5324491</td>\n",
       "      <td>黄智毅</td>\n",
       "      <td>0.09503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "3  acb7147b-533e-4699-ba5b-82db2494f4f6      徐旖芊     0.29269\n",
       "5  d7b8de6a-0960-424d-b455-06b5dab89ac8       李婷     0.20908\n",
       "7  e2c290d5-0e7b-4062-8604-c51a7e99443a      张铭睿     0.17849\n",
       "2  aad9040d-e1a8-4945-9a55-dd01156ea5fe      陈嘉仪     0.16209\n",
       "4  bd4ff60f-c33a-4e19-810c-d15059be5f5b      刘心如     0.15023\n",
       "8  23d81189-bac5-470e-8347-e9865d91303e      洪可凡     0.10100\n",
       "1  0c9db1fc-402b-44b7-b9f4-dbf30136451c      林嘉茵     0.10034\n",
       "9  48b98458-7be4-400d-ae28-99221d5c78e7      张梓乐     0.09990\n",
       "0  baeda9f7-fe2e-460b-9f7f-3b1415d7621b      丘某峰     0.09955\n",
       "6  fdcb99fd-00fe-4094-bc4f-fafee5324491      黄智毅     0.09503"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(faceListId_df, find_df,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
